/*
 * This file is part of Sui.
 *
 * Sui is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sui is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Sui.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Copyright (c) 2021 Sui Contributors
 */

package rikka.sui.ktx

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater

@SuppressLint("PrivateApi")
private val constructor = try {
    Class.forName("com.android.internal.policy.PhoneLayoutInflater").getDeclaredConstructor(Context::class.java).apply {
        isAccessible = true
    }
} catch (e: Throwable) {
    Log.e("LayoutInflaterKt", Log.getStackTraceString(e))
    null
}

fun createLayoutInflater(context: Context): LayoutInflater? {
    return try {
        constructor?.newInstance(context) as LayoutInflater?
    } catch (e: Throwable) {
        Log.e("LayoutInflaterKt", Log.getStackTraceString(e))
        null
    }
}
